package com.jiantong.version.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.version.impl.dao.DictionaryVersionDao;
import com.jiantong.version.model.DictionaryVersion;
import com.jiantong.version.service.DictionaryVersionReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by mz on 25/8/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class DictionaryVersionReadServiceImpl implements DictionaryVersionReadService{

    private final DictionaryVersionDao dictionaryVersionDao;

    @Autowired
    public DictionaryVersionReadServiceImpl(DictionaryVersionDao dictionaryVersionDao) {
        this.dictionaryVersionDao = dictionaryVersionDao;
    }

    /**
     * 查询所有
     *
     * @return List<DictionaryVersion>
     */
    @Override
    public Response<List<DictionaryVersion>> findAll() {
       try{
           return Response.ok(dictionaryVersionDao.findAll());
       }catch (Exception e){
           log.error("failed to find all dictionary version , case = {}", Throwables.getStackTraceAsString(e));
           return Response.fail("failed to find all dictionary version");
       }
    }


    /**
     * 查询app端的字典
     *
     * @return DictionaryVersion
     */
    @Override
    public Response<DictionaryVersion> findApp() {
        try{
            return Response.ok(dictionaryVersionDao.findForApp());
        }catch (Exception e){
            log.error("failed to find all dictionary version for app, case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to find all dictionary version for app");
        }
    }
}
